package com.hooda.server;

import com.hooda.container.Context;
import com.hooda.container.Host;

import java.io.IOException;
import java.io.InputStream;

public class Request {

    private String method;

    private String url;

    private String host;

    private InputStream inputStream;

    private Context context;

    private String contextName;

    private String urlPattern;

    public Request() {
    }

    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;

        int count = 0;
        while (count == 0) {
            count = inputStream.available();
        }

        byte[] bytes = new byte[count];
        inputStream.read(bytes);

        String data = new String(bytes);
        String firstLineStr = data.split("\\n")[0];
        String[] strs = firstLineStr.split(" ");
        method = strs[0];
        url = strs[1];

        String secondLineStr = data.split("\\n")[1];
        strs = secondLineStr.split(" ");
        host = strs[1].split(":")[0];
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public String getContextName() {
        return contextName;
    }

    public void setContextName(String contextName) {
        this.contextName = contextName;
    }

    public String getUrlPattern() {
        return urlPattern;
    }

    public void setUrlPattern(String urlPattern) {
        this.urlPattern = urlPattern;
    }
}
